package popoer.price.thief.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import popoer.price.thief.domain.Category;
import popoer.price.thief.service.Thief;
import popoer.price.thief.service.ThiefFactory;

@SuppressWarnings("serial")
public class CategoryServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setContentType("text/html;charset=utf-8");
		String type = req.getParameter("type");
		Thief jingDongThief = ThiefFactory.getTheif(type);
		try {
			List<Category> categories = jingDongThief.getCategories();
			req.setAttribute("categories", categories);
			req.getRequestDispatcher("/category.jsp").include(req, resp);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
